import { getDirectiveName } from '@/utils/importAll'

const modulesFiles = require.context('./', true, /\.js$/)
const directivesPath = modulesFiles.keys().reduce((modules, modulePath) => {
  const moduleName = getDirectiveName(modulePath)

  const value = modulesFiles(modulePath)
  modules[moduleName] = value.default
  return modules
}, [])

export default {
  install(Vue) {
    Object.keys(directivesPath).forEach(i => {
      if (directivesPath[i]) {
        Vue.directive(i, directivesPath[i])
      }
      if (window.Vue) {
        window[i] = directivesPath[i]
        Vue.use(install); // eslint-disable-line
      }
    })
  }
}
